# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=flatpak-builder
pkgver=1.1.1
pkgrel=1
pkgdesc="Tool to build flatpaks from source"
url="https://flatpak.org"
arch=(x86_64)
license=(LGPL)
depends=(flatpak binutils elfutils unzip tar git bzr patch rpmextract cpio appstream-glib)
makedepends=(intltool gobject-introspection git docbook-xsl xmlto libdwarf)
checkdepends=(valgrind)
replaces=('flatpak<0.9.10')
_commit=10658573f207effe4c8459f265fc9f111cff7739  # tags/1.1.1^0
source=("git+https://github.com/flatpak/flatpak-builder#commit=$_commit"
        "git+https://gitlab.gnome.org/GNOME/libglnx.git"
        "git+https://sourceware.org/git/debugedit.git")
sha256sums=('SKIP'
            'SKIP'
            'SKIP')

prepare() {
  cd $pkgname

  git submodule init
  git submodule set-url libglnx "$srcdir/libglnx"
  git submodule set-url debugedit "$srcdir/debugedit"
  git submodule update

  # https://github.com/flatpak/flatpak/issues/267
  sed -i '/locale\/C\./d' tests/make-test-runtime.sh

  NOCONFIGURE=1 ./autogen.sh
}

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/-/+/g'
}

build() {
  cd $pkgname

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib \
    --disable-static \
    --with-dwarf-header=/usr/include/libdwarf

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

check() {
  cd $pkgname
  make -k check
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install
}
